package com.leyou.gateway.limit;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author 虎哥
 */
@Component
public class IpKeyResolver implements KeyResolver {
    /**
     * 返回的是某个请求在redis中的key
     * @param exchange 上下文，里面封装了Request、Response等内容
     * @return 返回的就是一个key
     */
    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
        return Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
    }
}
